"""
简单围捕示例
"""

import numpy as np
import sys
import os

sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))

from usv_boids.core.simulation import Environment, SimulationEngine
from usv_boids.core.entities import Target
from usv_boids.utils.visualization import Visualizer, Plotter


def main():
    print("启动简单围捕示例...")
    
    # 创建环境
    env = Environment(width=100.0, height=100.0, boundary_mode='wrap')
    sim = SimulationEngine(env)
    
    # 添加目标
    target = Target(
        position=np.array([50.0, 50.0]),
        velocity=np.array([0.0, 0.0]),
        size=1.5
    )
    sim.add_target(target)
    
    # 添加无人艇
    sim.add_usv_fleet(
        count=12,
        spawn_area=(10.0, 10.0, 90.0, 90.0),
        speed_range=(0.8, 1.2),
        perception_radius=25.0
    )
    
    # 调整参数
    for usv in sim.usvs:
        usv.separation_weight=2.0
        usv.alignment_weight = 0.8
        usv.cohesion_weight=0.8
        usv.target_weight = 2.5
        usv.max_speed=1.6
        usv.max_force = 0.4
    
    vis = Visualizer(sim, show_metrics=True)
    vis.animate(frames=300, interval=50)
    
    print(Plotter.generate_report(sim))
    
    # 可选保存
    # Plotter.plot_metrics(sim, save_path="simple_surrounding_metrics.png")


if __name__ == "__main__":
    main() 